package grisar.gris.struct.enemy;

import grisar.gris.struct.Direction;
import grisar.gris.struct.MPoint;

import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;

public class Enemy implements I_Enemy {

	final static int tileSize=64; 
	int speed, slowspeed, prevspeed, health, slowtime;
	int nextTile=0, steps=0;
	boolean isDead;
	Bitmap bitmap;
	Point pos;
	List<MPoint> path;
	Direction dir;
	private Paint paint = new Paint();
	
	public Enemy(List<MPoint> path, Bitmap bitmap){
		
		this.bitmap = bitmap;
		speed = 0;
		this.pos = new Point(0,0);
		
	}
	
	//@Override
	public void draw(Canvas canvas) {

		canvas.drawBitmap(bitmap, pos.x, pos.y, paint);
	}

	//@Override
	public Point getPosition() {

		return pos;
	}
	
	public void setSpeed(int speed){
		
		this.speed = speed;
	}
	
	public int getSpeed(){
		
		return speed;
	}

	//@Override
	public void setPosition(Point pos) {

		this.pos = pos;
		dir = path.get(nextTile).nextDirection;
	}

	//@Override
	public void update() {
		
		if(steps==tileSize) {
			dir = path.get(nextTile).nextDirection;
			nextTile++;
			steps=0;
		}
		
		if(dir == Direction.left) {
			pos.x--;
		}
		else if(dir == Direction.right) {
			pos.x++;
		}
		else if(dir == Direction.up) {
			pos.y--;
		}
		else if(dir == Direction.down) {
			pos.y++;
		}
		else if(dir == Direction.end) {
			isDead = true;
		}
		
		steps++;
		
		if(slowtime>0)
			slowtime--;
		else if(slowtime==0)
			speed=prevspeed;

	}

	//@Override
	public void addNodeList(List<MPoint> list) {
			path = list;
		
	}

	public void reduceHP(int hp) {
		health -= hp;
		if(health<=0)
			isDead=true;
		
	}

	public void reduceSpeed(int speed, int time) {
		prevspeed=speed;
		this.speed=speed;
		this.slowtime = time;

		
	}

	public void setHp(int hp) {
		health = hp;
		
	}

	
}
